import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import locale from 'element-ui/lib/locale/lang/zh-CN' // lang i18n
import UmyUi from 'umy-ui'
  import 'umy-ui/lib/theme-chalk/index.css';// 引入样式

import '@/styles/index.scss' // global css
import ZkTable from 'vue-table-with-tree-grid'
import axios from 'axios'

import App from './App'
import store from './store'
import router from './router'
import './directive/dirlog'
import '@/icons' // icon
import '@/permission' // permission control
import Api from './api/index'
import config from './utils/config'
import dayjs from 'dayjs'
// 1. 全局挂载
import Print from './utils/print'
Vue.use(Print)
Vue.use(UmyUi);
// 2. 自定义指令
// import print from 'vue-print-nb'
// directives: {
//   print
// }

//自定义按钮权限指令
Vue.directive('permission', {
  inserted: function (el, binding, vnode) {
      let isExist = true
      if(binding.value){
        isExist = false;
      }
      // 从配置获取用户按钮权限
      let btnPermissions = store.getters.userInfo.buttons
      if (btnPermissions && btnPermissions.indexOf(binding.value) > -1) {
          isExist = true
      }
      //不存在时删除节点
      if (el.parentNode && !isExist) {
          el.parentNode.removeChild(el)
      }
  }
})
console.log(router)

Vue.prototype.dayjs = dayjs
Vue.prototype.$api = Api
Vue.prototype.$config = config
Vue.prototype.$axios = axios
// set ElementUI lang to EN
Vue.use(ElementUI, { locale })
Vue.use(ZkTable)
Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
